package com.chenfan.mcn.job;

import com.chenfan.mcn.config.UserVoContextHolder;
import com.chenfan.mcn.dao.ContractExcutionOrderMapper;
import com.chenfan.common.extension.xxljob.TenantIsolation;
import com.chenfan.mcn.utils.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 同步执行单回款状态
 * @author wulg
 * @date 2023/10/18
 */
@Slf4j
@Component
public class SyncExcutionOrderPaybackJob {

    @Value("${zxd_payback_effectiveTime:2023-08-30 22:30:00}")
    private String zxdPaybackEffectiveTimeStr;

    @Autowired
    private ContractExcutionOrderMapper contractExcutionOrderMapper;

    @TenantIsolation("同步执行单回款状态")
    @XxlJob(value = "syncExcutionOrderPayback")
    public ReturnT<String> execute(String param) {
        log.info("开始同步执行单回款状态！租户ID=" + UserVoContextHolder.getTenantId());
        Date zxdPaybackEffectiveTime = DateUtil.parseDate(zxdPaybackEffectiveTimeStr);
        contractExcutionOrderMapper.syncExcutionOrderPayback(zxdPaybackEffectiveTime);
        log.info("结束同步执行单回款状态！租户ID=" + UserVoContextHolder.getTenantId());
        /*log.info("开始同步执行单打款状态！租户ID=" + UserVoContextHolder.defaultTenantId());
        List<String> settlementMethodList = Arrays.asList(SettlementMethodEnum.SINGLE_RECEIVE_PAYMENT.getCode(), SettlementMethodEnum.BATCH_RECEIVE_PAYMENT.getCode());
        contractExcutionOrderMapper.syncExcutionOrderPaid(settlementMethodList, zxdPaybackEffectiveTime);
        log.info("结束同步执行单打款状态！租户ID=" + UserVoContextHolder.defaultTenantId());*/
        return ReturnT.SUCCESS;
    }
}
